package com.jinke.api.modules.ums.vo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.jinke.api.modules.ums.model.UmsAdmin;
import com.jinke.api.modules.ums.model.UmsResource;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 后台用户表
 * </p>
 *
 * @author macro
 * @since 2020-08-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "UmsAdmin对象", description = "后台用户表")
public class UmsAdminVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String username;

    @ApiModelProperty(value = "头像")
    private String icon;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "电话")
    private String phone;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "备注信息")
    private String note;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "最后登录时间")
    private Date loginTime;

    @ApiModelProperty(value = "帐号启用状态：0->禁用；1->启用")
    private Integer status;

    @ApiModelProperty(value = "姓名")
    private String realName;

    @ApiModelProperty(value = "公司")
    private String company;

    @ApiModelProperty(value = "保证金比例")
    private BigDecimal earnestRate;
    @ApiModelProperty(value = "利润费率")
    private BigDecimal profitRate;
    @ApiModelProperty(value = "角色名称")
    private List<String> roles;
    @ApiModelProperty(value = "微信号")
    private String wxId;
    @ApiModelProperty(value = "用户渠道列表")
    private List<UserChannelVO> userChannels;
    @ApiModelProperty(value = "邀请码")
    private String invitationCode;

    @ApiModelProperty(value = "信用额度，美元")
    private BigDecimal creditBalance;
    @ApiModelProperty(value = "对应销售信息")
    private UmsAdmin seller;
    @ApiModelProperty(value = "可用信用额度，美元")
    private BigDecimal availableCreditBalance;
    @ApiModelProperty(value = "用户渠道列表")
    private List<UmsResource> resources;


    @ApiModelProperty(value = "剩余金额，美元")
    private BigDecimal balance;
    @ApiModelProperty(value = "保证金，美元")
    private BigDecimal earnestBalance;
    @ApiModelProperty(value = "押金，美元")
    private BigDecimal depositBalance;
    @ApiModelProperty(value = "待退款金额，美元")
    private BigDecimal refundAmount;

    public BigDecimal getAvailableCreditBalance(){
        if (balance!=null){
            //表中没设置值此处影响登录 所以加校验
            if(BigDecimal.ZERO.compareTo(balance) >0){
                return creditBalance.add(balance);
            }
        }
        return creditBalance;
    }
}
